// 地图解析和管理
// 这是一个单例类

#ifndef ALICE_MAP_MAP_MANAGER_H_
#define ALICE_MAP_MAP_MANAGER_H_

#include <map>
#include <iostream>
#include <string>

#include <SDL.h>
#include "tinyxml.h"

#include "game_map.h"
#include "tile_layer.h"

namespace alice {

class MapManager {
  public:
    static MapManager* GetInstance() {
      return instance_ = (instance_ == nullptr ? new MapManager() : instance_); 
    }

    bool Load();
    void Clean();
    GameMap* GetMap(std::string id) { return maps_[id]; }

  private:
    MapManager() {}
    bool Parse(std::string id, std::string source);
    TileSet ParseTileSet(TiXmlElement* xml_tile_set);
    TileLayer* ParseTileLayer(TiXmlElement* xml_layer, TileSetList tile_set, int tile_size, int row, int columns);

  private:
    static MapManager* instance_;
    std::map<std::string, GameMap*> maps_;
};

}

#endif